﻿#region File Header
/***********************************************************************
 * Copyright © 2013 Beals Software
 * All Rights Reserved
************************************************************************
Author: Donald Beals
Date: February 4th, 2013
Description: TODO: Write a description of this file here.
****************************** Change Log ******************************
02.04.13 - Created initial file. (dbeals)
02.18.13 - Added EnsureDirectoryExists() and GetDefaultCacheFolder(). (dbeals)
***********************************************************************/
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameJolt.Async;
#endregion

namespace GameJoltServices
{
	/// <summary>
	/// 
	/// </summary>
	public static class Helper
	{
		static Helper()
		{
		}

		public static bool GameDataStoreExists(string gameID, string privateKey, string dataStoreKey)
		{
			var keys = GameJolt.DataStore.GetKeys(gameID, privateKey, null, null, GameJolt.DataStoreType.Game);
			if(keys == null || keys.Length == 0)
				return false;

			return keys.Contains(dataStoreKey);
		}

		public static bool UserDataStoreExists(string gameID, string privateKey, string username, string userToken, string dataStoreKey)
		{
			var keys = GameJolt.DataStore.GetKeys(gameID, privateKey, username, userToken, GameJolt.DataStoreType.User);
			if(keys == null || keys.Length == 0)
				return false;

			return keys.Contains(dataStoreKey);
		}

		public static bool EnsureDirectoryExists(string fullPath)
		{
			if(System.IO.Path.HasExtension(fullPath))
				fullPath = System.IO.Path.GetDirectoryName(fullPath);

			if(System.IO.Directory.Exists(fullPath))
				return true;
			System.IO.Directory.CreateDirectory(fullPath);
			return false;
		}

		public static string GetDefaultCacheFolder(string gameFolder)
		{
#if PLATFORM_PC
			return System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", gameFolder);
#elif PLATFORM_ANDROID
				return System.IO.Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath, gameFolder);
#endif
		}
	}
}
